package com.ruoyi.miniapp.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.miniapp.domain.Bed;
import com.ruoyi.miniapp.domain.Order;
import com.ruoyi.miniapp.domain.vo.OrderVO;
import com.ruoyi.miniapp.service.IOrderService;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/apporder")
public class AppOrderController {

    @Resource
    private IOrderService orderService;

    @PostMapping("createOrder")
    public AjaxResult createOrder(@RequestBody Bed bed) {
        AjaxResult result = orderService.createOrderFromLogin(bed.getBedCode());
        return result;
    }

    /**
     * 结束订单
     *
     * @param orderId
     * @return
     */
    @PutMapping("endingOrder/{orderId}")
    public AjaxResult endingOrder(@PathVariable("orderId") Long orderId) {
        return orderService.updateOrderToEnd(orderId);
    }

    /**
     * 订单支付
     */
    @PutMapping("payOrder/{orderId}")
    public AjaxResult payOrder(@PathVariable("orderId") Long orderId) {
        return orderService.payOrder(orderId);
    }

    /**
     * 获取当前用户的所有订单
     */
    @GetMapping("selectOrder/{status}")
    public R<List<Order>> selectOrderPersonal(@PathVariable("status") Long status) {
        List<Order> orderList = orderService.selectAllOrderPersonal(status);
        return R.ok(orderList);
    }

    @GetMapping("orderDetail/{orderId}")
    public AjaxResult getOrderDetail(@PathVariable("orderId") Long orderId) {
        OrderVO orderVO = orderService.getOrderDetail(orderId);
        return AjaxResult.success(orderVO);
    }
}
